<script>
import {deleteLogBatch, getConversationPageList, getPageList} from "@/api/aihuman/log/log";
import LogPreview from "@/views/aihuman/log/LogPreview.vue";

export default {
  name: "LogView",
  components: {LogPreview},
  data() {
    return {
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
        pageSizes: [10, 20, 30, 40, 50, 100],
      },
      tableData: [],
      tableOptions: {
        //新增按钮
        addBtn: false,
        header: false,
        viewBtn: false,
        delBtn: false,
        editBtn: false,
        refreshBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        stripe: false,
        selection: true,
        height:'auto',
        tip: false,
        // simplePage: false,
        searchMenuSpan: 8,
        border: true,
        index: true,
        indexWidth: 60,
        indexLabel: "序号",
        menuWidth: 100,
        menu: true,
        align: "center",
        menuAlign: "left",
        dialogWidth: "40%",
        dialogClickModal: false,
        dialogType: "drawer",
        span: 24,
        dialogCustomClass: "huilan-drawer-form",
        emptyText: this.$t('aicosCommon.notData'),
        column: [
          {
            label: "会话ID",
            prop: "conversation",
            overHidden: true
          },
          {
            label: "房间",
            prop: "room",
            overHidden: true
          },
          {
            label: "开始时间",
            prop: "beginTime",
            overHidden: true

          },
          {
            label: "结束时间",
            prop: "endTime",
            overHidden: true

          },
          // {
          //   label: "用户名",
          //   prop: "user_name",
          //   overHidden: true
          //
          // },
          // {
          //   label: "用户id",
          //   prop: "user_id",
          //   overHidden: true
          //
          // }, {
          //   label: "数字人数据",
          //   prop: "metadata",
          //   overHidden: true,
          //   minWidth: 180
          //
          // }, {
          //   label: "机器人实例",
          //   prop: "transfiguration",
          //   overHidden: true,
          //   minWidth: 200
          // }, {
          //   label: "会话ID",
          //   prop: "conversation",
          //   overHidden: true
          // },
          // {
          //   label: '创建时间',
          //   prop: 'createTime',
          //   minWidth: 200
          // }
        ],
      },
      selectedList: [],
      searchForm: {},
      searchFieldList: [
        {
          prop: 'room',
          placeholder: '请输入房间'
        }
      ]
    }
  },
  created() {
    this.getList()
  },
  methods: {
    openPreview(row) {
      this.$refs.logPreview.open(row)
    },
    searchFn() {
      this.getList()
    },
    selectionChange(val) {
      this.selectedList = val
    },
    currentChange(current) {
      this.page.currentPage = current
      this.getList()
    },
    sizeChange(size) {
      this.page.pageSize = size
      this.getList()
    },
    getList() {
      this.$nextTick(async () => {
        try {
          let params = {
            pageNo: this.page.currentPage,
            pageSize: this.page.pageSize,
            ...this.searchForm
          }
          const {data} = await getConversationPageList(params)
          this.tableData = data.data.records
          this.page.total = data.data.total
        } catch (e) {
          console.log(e);
        }

      })
    },
    configColumn() {
      this.$refs.listRef.$refs.dialogColumn.columnBox = true;
    },
    async batchRemove() {
      if (this.selectedList.length === 0) {
        this.$message({
          type: "warning",
          message: "请选择需要处理的数据",
        });
        return false
      }

      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        let ids = this.selectedList.map(item => item.id)

        let params = {
          ids: ids.join(",")
        }
        const {data} = await deleteLogBatch(params)
        this.$message({
          type: 'success',
          message: data.msg
        })
        this.selectedList = []
        this.getList()
      });

    },
  }
}
</script>

<template>
  <huilan-basic>
    <HuilanBasicToolbar style="margin-top: 0">

      <el-button type="danger" size="small" @click="batchRemove">
        批量删除
      </el-button>
    </HuilanBasicToolbar>
    <HuilanBasicSearchbar :model="searchForm" :fields="searchFieldList" @search="searchFn" @reset="getList">
      <template v-slot:appendTool>
        <el-button type="default" @click="configColumn"><i class="el-icon-s-operation"></i></el-button>
      </template>
    </HuilanBasicSearchbar>
    <avue-crud
      ref="listRef"
      :option="tableOptions"
      :page.sync="page"
      :data="tableData"
      @current-change="currentChange"
      @size-change="sizeChange"
      @selection-change="selectionChange"
    >
      <template slot-scope="scope" slot="menu">
        <el-button type="text" @click="openPreview(scope.row)">查看详情</el-button>
      </template>

    </avue-crud>

    <log-preview
      ref="logPreview"
    />
  </huilan-basic>
</template>

<style scoped lang="scss">

</style>
